package com.sky.es.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

import javax.persistence.Id;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author yangsk
 */
@Data
@NoArgsConstructor
@Document(indexName = "product",createIndex = true)
public class ProductDoc {
    @Id
    private Long id;
    @Field(type = FieldType.Text,analyzer = "ik_smart")
    private String name;
    @Field(type = FieldType.Text,analyzer = "ik_smart")
    private String desc;
    @Field(type = FieldType.Double)
    private BigDecimal price;
    @Field(type = FieldType.Keyword)
    private String type;
    @Field(type = FieldType.Keyword)
    private String lv;
    @Field(type = FieldType.Keyword)
    private List<String> tages;
    @Field(type = FieldType.Keyword)
    private String region;
    @Field(type = FieldType.Date,format =DateFormat.custom,pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    @Field(type = FieldType.Date,format = DateFormat.custom,pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    @GeoPointField
    private GeoPoint location;
    /**
     * 推荐搜索
     */
    @CompletionField(analyzer = "ik_smart")
    private List<String> suggestionTest;

    public void setSuggestionTest(List<String> suggestionTest) {
        ArrayList<String> strings = new ArrayList<>();
        strings.add(this.name);
        strings.add(this.desc);
        this.suggestionTest = strings;
    }
/*public ProductDoc(Product product) {
        this.id = product.getId();
        this.name = product.getName();
        this.desc = product.getDesc();
        this.price = product.getPrice();
        this.type = product.getType();
        this.tages = product.getTages();
        this.createTime = product.getCreateTime();
        this.location = new GeoPoint(product.getLongitude(),product.getLatitude());
    }*/
}
